/**
 入驻小区
 **/
(function (vc) {
    var DEFAULT_PAGE = 1;
    var DEFAULT_ROWS = 10;
    vc.extends({
        data: {
            housekeepingTypeInfo: {
                housekeepingTypes: [],
                total: 0,
                records: 1,
                moreCondition: false,
                hktId: '',
                isShows: [],
                conditions: {
                    ispublic: '',
                    hktName: '',
                    isShow: '',
                    shopId: vc.getCurrentCommunity().shopId,
                    typeCd: '1001'
                }
            }
        },
        _initMethod: function () {
            $that._listHousekeepingTypes(DEFAULT_PAGE, DEFAULT_ROWS);
            vc.getDict('housekeeping_type', "is_show", function (_data) {
                $that.housekeepingTypeInfo.isShows = _data;
            });
        },
        _initEvent: function () {
            vc.on('housekeepingType', 'listHousekeepingType', function (_param) {
                $that._listHousekeepingTypes(DEFAULT_PAGE, DEFAULT_ROWS);
            });
            vc.on('pagination', 'page_event', function (_currentPage) {
                $that._listHousekeepingTypes(_currentPage, DEFAULT_ROWS);
            });
        },
        methods: {
            _listHousekeepingTypes: function (_page, _rows) {
                $that.housekeepingTypeInfo.conditions.page = _page;
                $that.housekeepingTypeInfo.conditions.row = _rows;
                var param = {
                    params: $that.housekeepingTypeInfo.conditions
                };
                param.params.hktName = param.params.hktName.trim();
                //发送get请求
                vc.http.apiGet('/housekeepingType.queryHousekeepingType',
                    param,
                    function (json, res) {
                        let _json = JSON.parse(json);
                        $that.housekeepingTypeInfo.total = _json.total;
                        $that.housekeepingTypeInfo.records = _json.records;
                        $that.housekeepingTypeInfo.housekeepingTypes = _json.data;
                        vc.emit('pagination', 'init', {
                            total: $that.housekeepingTypeInfo.records,
                            dataCount: $that.housekeepingTypeInfo.total,
                            currentPage: _page
                        });
                    }, function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _openAddHousekeepingTypeModal: function () {
                vc.emit('addHousekeepingType', 'openAddHousekeepingTypeModal', {});
            },
            _openEditHousekeepingTypeModel: function (_housekeepingType) {
                vc.emit('editHousekeepingType', 'openEditHousekeepingTypeModal', _housekeepingType);
            },
            _openDeleteHousekeepingTypeModel: function (_housekeepingType) {
                vc.emit('deleteHousekeepingType', 'openDeleteHousekeepingTypeModal', _housekeepingType);
            },
            //查询
            _queryHousekeepingTypeMethod: function () {
                $that._listHousekeepingTypes(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            //重置
            _resetHousekeepingTypeMethod: function () {
                $that.housekeepingTypeInfo.conditions.hktName = "";
                $that.housekeepingTypeInfo.conditions.isShow = "";
                $that.housekeepingTypeInfo.conditions.ispublic = "";
                $that._listHousekeepingTypes(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            _moreCondition: function () {
                if ($that.housekeepingTypeInfo.moreCondition) {
                    $that.housekeepingTypeInfo.moreCondition = false;
                } else {
                    $that.housekeepingTypeInfo.moreCondition = true;
                }
            }
        }
    });
})(window.vc);
